<template>
  <div>

    <el-form :model="cus">
      <el-form-item label="姓名" :label-width="formLabelWidth">
        <el-input v-model="cus.cusName" placeholder="请输入名称" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" :label-width="formLabelWidth">
        <el-input v-model="cus.cusPho" placeholder="请输入联系电话" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="地址" :label-width="formLabelWidth">
        <el-input v-model="cus.cusAdd" placeholder="请输入地址" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="邮编" :label-width="formLabelWidth">
        <el-input v-model="cus.cusPost" placeholder="请输入邮编" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="账户名" :label-width="formLabelWidth">
        <el-input v-model="cus.userName" placeholder="请输入账户名" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="密码" :label-width="formLabelWidth">
        <el-input v-model="cus.password" placeholder="请输入密码" autocomplete="off" :disabled="true"> </el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dialogFormVisible = true;">修改</el-button>
    </div>


    <el-dialog title="个人信息" :visible.sync="dialogFormVisible">
      <el-form :model="cus">
        <el-form-item label="姓名" :label-width="formLabelWidth">
          <el-input v-model="cus.cusName" placeholder="请输入名称" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" :label-width="formLabelWidth">
          <el-input v-model="cus.cusPho" placeholder="请输入联系电话" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址" :label-width="formLabelWidth">
          <el-cascader style="float: left"
                       size="large"
                       :options="pcaTextArr"
                       v-model="selectedOptions">
          </el-cascader>
        </el-form-item>

        <el-form-item label="详细地址" :label-width="formLabelWidth">
          <el-input v-model="cus.cusAdd" placeholder="请输入地址" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮编" :label-width="formLabelWidth">
          <el-input v-model="cus.cusPost" placeholder="请输入邮编" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="账户名" :label-width="formLabelWidth">
          <el-input v-model="cus.userName" placeholder="请输入账户名" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="cus.password" placeholder="请输入密码" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false;">取 消</el-button>
        <el-button type="primary" @click="add()">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import {addCustomer, changeCustomer} from "@/api/customer";
import {getInfo} from "@/api/customer";
import {pcaTextArr} from 'element-china-area-data'

export default {
  data() {
    return {
      formLabelWidth: "120px",
      dialogFormVisible: false, //控制对话框是否可见
      dialogForm2Visible: false, //控制对话框是否可见
      cus: {//新增和编辑
        cusCode: "",
        cusName: "",
        cusPho: "",
        cusAdd: "",
        cusPost: "",
        userName: "",
        password: "",
      },
      pcaTextArr,
      selectedOptions: []
    };
  },

  methods: {


    add() {
      const {cus} = this;
      if (!cus.cusCode || !cus.cusName || !cus.cusPho || !cus.cusAdd || !cus.cusPost) {
        this.$message("请完整填写");
      } else {
        changeCustomer(this.cus).then((res) => {
          if (res.data.code === 1) {
            this.$message.success("修改成功")
            this.dialogFormVisible = false
          }
        }).catch((e) => {
        })
      }

    },

    get() {
      getInfo().then((res) => {
        this.cus = res.data.data;
      }).catch((e) => {
      })
    }


  },
  mounted() {
    this.get();
  },


  watch: {
    selectedOptions(e) {
      // 当selected值发生变化时执行
      this.cus.cusAdd = e[0] + e[1] + e[2];
    }
  }
};
</script>
<style>

</style>
